<template>
	<view>
		<view-head Title="血压" :isShowR="true" @saveBack="saveBack"></view-head>
		<view class="view-content">
			<view class="time-box _df _jb _ac" @click="show=true">
				<view class="name">
					测量时间
				</view>
				<view class="time">
					{{time}}<u-icon name="arrow-right" class="ml15" color="#aaa" size="28"></u-icon>
				</view>
			</view>
			<view class="subTitle">
				血压（必填）
			</view>
			<view class="list">
				<view class="item">
					<view class="title">
						收缩压（高压）
					</view>
					<view class="input-box _df _jb _ac">
						<u-input v-model.number="page.currentSs" placeholder="请输入" :clearable="false" type="text" :border="false" />
						<view class="dw">
							mmHg
						</view>
					</view>
				</view>
				<view class="item">
					<view class="title">
						舒张压（低压）
					</view>
					<view class="input-box _df _jb _ac">
						<u-input v-model.number="page.currentFz" placeholder="请输入" :clearable="false" type="text" :border="false" />
						<view class="dw">
							mmHg
						</view>
					</view>
				</view>
			</view>
			<!-- <view class="subTitle">
				脉搏（选填）
			</view>
			<view class="list">
				<view class="item">
					<view class="title">
						脉搏
					</view>
					<view class="input-box _df _jb _ac">
						<u-input v-model="value3" placeholder="请输入" :clearable="false" type="text" :border="false" />
						<view class="dw">
							次/分
						</view>
					</view>
				</view>
			</view> -->
		</view>
		<u-picker v-model="show" mode="time" :params="params" @confirm="change"></u-picker>
	</view>
</template>

<script>
	import moment from "moment";
	export default {
		data() {
			return {
				value:'',
				value2:'',
				value3:'',
				show:false,
				time:moment().format('MM-DD HH:mm'),
				mode:'date',
				params: {
					year: false,
					month: true,
					day: true,
					hour: true,
					minute: true,
					second: false
				},
				page:{
					currentSs:null,
					currentFz:null,
					createTime:moment().format('YYYY-MM-DD HH:mm'),
					interval_index: 0, //间隔时间
					totalSteps: 0, //总计步
					totalHeat: 0, //总热量(千卡)
					totalDistance: 0, //总距离(千米)
					totalSleep: 0, //总睡眠(分钟)
					totalDeepSleep: 0, //深睡（分钟）
					totalLightSleep: 0, // 浅睡（分钟）
					currentHeartRate: 0, //心率（次/分钟）
					currentBloodOxygen: 0, //血氧饱和度
					currentPressure: 0, //压力
					currentMet: 0, //梅脱
					currentMai: 0, //MAI
					currentTemp: 0, //温度（0.1摄氏度）
					currentBloodSugar: 0, //血糖（0.1）
					motionDuration: 0, //运动时长
					longitude: '',
					latitude: '',
					address: '',
				}
			};
		},
		onLoad() {
			
		},
		onShow() {
			
		},
		methods:{
			addData(){
				let that = this
				if(this.page.currentSs == null){
					uni.showToast({
						title:'请填写收缩压',
						icon:'none'
					})
					return
				}
				if(this.page.currentFz == null){
					uni.showToast({
						title:'请填写舒张压',
						icon:'none'
					})
					return
				}
				uni.$_post({
					url: "addHealthData",
					that: that,
					params: that.page,
					success(res) {
						console.log(res)
						if(res.code == 0){
							that.$u.toast(res.msg)
							setTimeout(()=>{
								uni.navigateBack()
							},1000)
						}else{
							uni.showToast({
								title: '添加失败',
								duration: 2000,
								icon:'error'
							});
						}
					},
					fail(err) {
						uni.showToast({
							title: '添加失败',
							duration: 1000,
							icon:'error'
						});	
					},
				});
			},
			saveBack(){
				this.addData()
			},
			change(e){
				let year = new Date().getFullYear()
				this.time = e.month+ '-' + e.day +' '+ e.hour + ':' +e.minute
				this.page.createTime = year + '-' + e.month+ '-' + e.day +' '+ e.hour + ':' +e.minute
			}
		},
	}
</script>

<style lang="scss" scoped>
	/deep/.u-btn--primary{
		background-color: #FF4651;
		border-color: #FF4651;
	}
.view-content{
	padding: 0 50rpx 80rpx;
	.time-box{
		margin-bottom: 60rpx;
		.name{
			font-size: 34rpx;
			font-family: $uni-font-family-Bold;
			color: #000;
		}
		.time{
			font-size: 28rpx;
			font-family: $uni-font-family-Medium;
			color: #aaa;
		}
	}
	.subTitle{
		font-size: 24rpx;
		font-family: $uni-font-family-Medium;
		color: #888;
		margin-bottom: 24rpx;
	}
	.list{
		display: grid;
		grid-template-columns: 1fr 1fr;
		grid-column-gap: 20rpx;
		margin-bottom: 40rpx;
		.item{
			height: 220rpx;
			background: #f5f5f5;
			border-radius: 30rpx;
			padding: 50rpx 50rpx 0 40rpx;
			.title{
				font-size: 24rpx;
				font-family: $uni-font-family-Medium;
				color: #888;
				margin-bottom: 30rpx;
			}
			.dw{
				font-size: 30rpx;
				font-family: $uni-font-family-Medium;
				color: #111;
				margin-left: 10rpx;
			}
			/deep/.uni-input-input{
				font-size: 60rpx;
				font-family: $uni-font-family-Bold;
				color: #000;
			}
		}
	}
}
</style>
